Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports C4F.DevKit.Messaging
Namespace MapiApplication
	Public Partial Class Credential
	Inherits Form
		Private manager As MapiManager
		Private credentialList As List(Of String)
		Public Sub New()
			InitializeComponent()
		End Sub
		Public Sub New(ByRef manager As MapiManager, ByRef credentialList As List(Of String))
			InitializeComponent()
			Me.manager = manager
			If credentialList Is Nothing Then
				credentialList = New List(Of String)()
			End If
			Me.credentialList = credentialList
			If Me.credentialList IsNot Nothing Then
				If credentialList.Count > 0 Then
					txtUsername.Text = credentialList(0)
					txtPassword.Text = credentialList(1)
					txtHost.Text = credentialList(2)
					txtPort.Text = credentialList(3)
				End If
			End If
		End Sub
		Private Sub btnCreate_Click(ByVal sender As Object, ByVal e As EventArgs)
			If String.IsNullOrEmpty(txtUsername.Text) Then
				MessageBox.Show("Username can not be empty.")
				Return
			End If
			If String.IsNullOrEmpty(txtPassword.Text) Then
				MessageBox.Show("Password can not be empty.")
				Return
			End If
			If String.IsNullOrEmpty(txtHost.Text) Then
				MessageBox.Show("Host can not be empty.")
				Return
			End If
			If String.IsNullOrEmpty(txtPort.Text) Then
				MessageBox.Show("Port can not be empty.")
				Return
			End If
			Dim portResult As UInt32
			If Not UInt32.TryParse(txtPort.Text, portResult) Then
				MessageBox.Show("Port should be integer", "Credential", MessageBoxButtons.OK, MessageBoxIcon.Information)
				Return
			End If
            credentialList.Insert(0, txtUsername.Text)
            credentialList.Insert(1, txtPassword.Text)
            credentialList.Insert(2, txtHost.Text)
            credentialList.Insert(3, txtPort.Text)
            manager.CreateCredentialsToSendMail(txtUsername.Text, txtPassword.Text, txtHost.Text, CType(portResult, Int32))
			Me.Close()
		End Sub
		Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As EventArgs)
			Me.Close()
		End Sub
	End Class
End Namespace
